<?php if (!isset($_SESSION)) session_start(); ?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">

<title>Koreanet</title>

<!-- Nanum Webfont -->
<style>
* {
	font-family: 'NanumGothic' !important;
}
</style>
<script src="http://www.google.com/jsapi"></script>
<script>
 google.load( "webfont", "1" );
 google.setOnLoadCallback(function() {
  WebFont.load({ custom: {
   families: [ "NanumGothic" ],
   urls: [ "http://fontface.kr/NanumGothic/css" ]
  }});
 });
</script>

<!-- Bootstrap core CSS -->
<link href="./dist/css/bootstrap.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="./css/admin.css" rel="stylesheet">


<link rel="stylesheet"
	href="./lib/tablesorter-master/css/theme.blue.css">
<link rel="stylesheet"
	href="./lib/datetimepicker/bootstrap-datetimepicker.min.css" />
</head>

<body>
<?php include 'header.php';?>
<?php

if ($login == null || $login->getGrade () > 2) {
	echo "<script type='text/javascript'>";
	echo "location.replace('./main.php');";
	echo "</script>";
	exit ();
}
?>

<script type="text/javascript">
	var reVal;
	function requestTableData() {
		$("#table").trigger("destroy");
		reVal = getXMLRequestObject();
		reVal.onreadystatechange = onChange;
		var table = document.getElementById("table_selection");
		var op1 = document.getElementById("opDelemiter");
		var inputText = document.getElementById("inputText");
		var p1val = document.getElementById("p1val");
		var p2val = document.getElementById("p2val");
		var params = "table="+table.value+"&op1="+op1.value+"&text="+inputText.value+"&p1val="+p1val.value+"&p2val="+p2val.value;
		//document.getElementById("container").innerText = op1 + " = " + inputText;
		reVal.open("POST", "./ajax/admin_table.php", true);
		reVal.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// 		reVal.setRequestHeader("Content-length", params.length);
// 		reVal.setRequestHeader("Connection", "close");
		reVal.send(params);
	}

	function getXMLRequestObject() {
		var xmlreq = false;
		if (window.XMLHttpRequest) { //파이어폭스나 맥의 사파리의 경우처리 
			xmlreq = new XMLHttpRequest();
		} else if (window.ActiveXObject) { //IE계열의 브라우져의 경우
			try {
				xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e1) {
				// Failed to create required ActiveXObject
				try {
					// Try version supported by older versions
					// of Internet Explorer
					xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
					// Unable to create an XMLHttpRequest with ActiveX
				}
			}
		}
		return xmlreq;
	}

	function onChange() {
		// only if req shows "loaded"
		if (reVal.readyState == 4) {
			// only if "OK"
			if (reVal.status == 200) {
				$("#table").trigger("destroy");
				if (document.getElementById("table_selection").value == "1") {
					document.getElementById("table_div").innerHTML = "<table id='table' class='table table-hover tablesorter'><thead id='table_head'><tr><th>사원번호</th><th>성명</th><th>운전면허번호</th><th>화물자격번호</th><th>사업자등록번호</th><th>회원등급</th><th>직책</th><th>운송료결산일</th><th>이메일</th><th>주소</th><th>차량</th><th>연락처</th><th>기본 운송료</th></tr></thead><tbody id='tbodyInfo'></tbody></table>";
				} else if (document.getElementById("table_selection").value == "2") {
					document.getElementById("table_div").innerHTML = "<table id='table' class='table table-hover tablesorter'><thead id='table_head'><tr><th>차량식별 번호</th><th>차량등록 번호판</th><th>차대 번호</th><th>차량소속</th><th>번호판 소유</th><th>탑 형식</th><th>현재기사</th></tr></thead><tbody id='tbodyInfo'></tbody></table>";
				} else if (document.getElementById("table_selection").value == "3") {
					document.getElementById("table_div").innerHTML = "<table id='table' class='table table-hover tablesorter'><thead id='table_head'><tr><th>날짜</th><th>사원번호</th><th>성명</th><th>직책</th><th>자동차등록번호판</th><th>차량식별번호</th><th>거래처명</th><th>근무점포</th><th>근태</th></tr></thead><tbody id='tbodyInfo'></tbody></table>";
				} else {
					document.getElementById("table_div").innerHTML = "<table id='table' class='table table-hover tablesorter'><thead id='table_head'><tr><th>날짜</th><th>사원번호</th><th>성명</th><th>소유구분</th><th>총운송료</th><th>공제금액</th><th>지급액</th><th>결산일</th><th>결산완료</th><th>거래은행</th><th>예금주</th><th>계좌번호</th></tr></thead><tbody id='tbodyInfo'></tbody></table>";
				}
				if (reVal.responseText.length < 1) {
					alert("검색 결과가 없습니다.");
					document.getElementById("tbodyInfo").innerHTML = "";
				} else {
					document.getElementById("tbodyInfo").innerHTML = reVal.responseText;
				}
				addTableSorter();
			} else {
				alert("There was a problem retrieving the XML data:\n" + reVal.statusText);
			}
		}
	}

	function resort() {
		var resort = true;
		$("#table").trigger("updateAll", [resort]);
	}

	function addTableSorter() {
		$("#table")
		.tablesorter({
			theme : 'blue',
			widthFixed: false,
			sortInitialOrder: "asc",
			cssChildRow: "tablesorter-childRow",
			showProcessing: true,
			initWidgets: true,
			widgets: ['pager', /*'stickyHeaders',*/ 'filter'],
			widgetOptions: {
				pager_output: 'Current {startRow} to {endRow} (total:{totalRows})',
				pager_updateArrows: true,
				pager_startPage: 0,
				pager_size: 10,
				pager_savePages: true,
				pager_fixedHeight: false,
				pager_removeRows: false,
				pager_ajaxUrl: null,
				pager_customAjaxUrl: function(table, url) { return url; },
				pager_ajaxObject: { dataType: 'json' },
				pager_ajaxProcessing: function(ajax){ return [ 0, [], null ]; },
				pager_css: {
					container   : 'tablesorter-pager',
					errorRow    : 'tablesorter-errorRow',
					disabled    : 'disabled'
				},
				pager_selectors: {
					container   : '.pager',
					first       : '.first',
					prev        : '.prev',
					next        : '.next',
					last        : '.last',
					goto        : '.gotoPage', //이 줄 에러는 이클립스에서만 나는 것이니 신경쓰지 말 것
					pageDisplay : '.pagedisplay',
					pageSize    : '.pagesize'
				},
				/*stickyHeaders : '',
				stickyHeaders_offset : 0,
				stickyHeaders_cloneId : '-sticky',
				stickyHeaders_addResizeEvent : true,
				stickyHeaders_includeCaption : true,
				stickyHeaders_zIndex : 2,
				stickyHeaders_attachTo : null*/
		}
	})

	.bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
		var p = c.pager,
		msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
			' page <span class="typ">' + (p.page + 1) + '/' + p.totalPages + '</span>';
		$('#display')
			.append('<li><span class="str">"' + e.type + msg + '</li>')
			.find('li:first').remove();
	})

// 	$('.tablesorter-childRow td').hide();
// 	$('.tablesorter').delegate('.toggle', 'click' ,function(){
// 		$(this).closest('tr').nextUntil('tr:not(.tablesorter-childRow)').find('td').toggle();
// 		return false;
// 	});
	}

	function changeDelemiter(obj) {
		if (obj.value == "1") {
			document.getElementById("opDelemiter").innerHTML = "<option value='1'>사원번호</option><option selected='selected' value='2'>성명</option><option value='3'>이메일</option><option value='5'>연락처</option><option value='6'>운전면허번호</option><option value='7'>화물자격번호</option><option value='8'>사업자등록번호</option>";
			document.getElementById("search_date").style.display = "none";
		} else if (obj.value == "2") {
			document.getElementById("opDelemiter").innerHTML = "<option value='1'>차량식별번호</option><option selected='selected' value='8'>차량등록번호판</option><option value='3'>차대번호</option>";
			document.getElementById("search_date").style.display = "none";
		} else if (obj.value == "3") {
			document.getElementById("opDelemiter").innerHTML = "<option value='1'>사원번호</option><option selected='selected' value='2'>성명</option>";//<option value='3'>이메일</option><option value='4'>주소</option><option value='5'>연락처</option>";
			document.getElementById("search_date").style.display = "inherit";
		} else {
			document.getElementById("opDelemiter").innerHTML = "<option value='1'>사원번호</option><option selected='selected' value='2'>성명</option>";//<option value='3'>날짜</option>";
			document.getElementById("search_date").style.display = "inherit";
		}
	}
</script>

	<div class="container container_bottom">
		<div class="row">
			<div class="col-md-12">
				<h2>관리자</h2>
			</div>
		</div>
		<div class="row">
			<div class="col-md-8">
				<div class="input-group-wrapper">
					<div class="input-group">
						<span class="input-group-addon">대상</span> <select
							class="form-control" id="table_selection"
							onchange="javascript:changeDelemiter(this)">
							<option selected="selected" value="1">인력</option>
							<option value="2">차량</option>
							<option value="3">일결산</option>
							<option value="4">월결산</option>
						</select>
					</div>
				</div>
				<div class="input-group-wrapper">
					<div class="input-group">
						<span class="input-group-addon">구분</span> <select
							class="form-control" id="opDelemiter">
							<option selected='selected' value='1'>사원번호</option>
							<option value='2'>성명</option>
							<option value='3'>이메일</option>
							<!-- <option value='4'>주소</option> -->
							<option value='5'>연락처</option>
							<option value='6'>운전면허번호</option>
							<option value='7'>화물자격번호</option>
							<option value='8'>사업자등록번호</option>
							<!-- <option value='9'>거래처</option> -->
						</select>
					</div>
				</div>
				<div class="input-group-wrapper_search">
					<div class="input-group">
						<input type="text" class="form-control" id="inputText"
							onkeydown="javascript:if(event.keyCode==13){requestTableData();}">
						<span class="input-group-btn">
							<button class="btn btn-default btn_search" type="button"
								onclick="requestTableData()">검색</button>
						</span>
					</div>
				</div>
				<div id="search_date">
					<div class="input-group-wrapper first_wrapper">
						<div class='input-group date' id='picker1'>
							<span class='input-group-addon'>기간</span> <input id='p1val'
								type='text' class="form-control" data-format='YYYY/MM/DD'
								readonly='readonly'
								value="<?php echo date('Y/m/d',strtotime('-1 day'));?>" /> <span
								class='input-group-addon input-group-addon-end'>
								<button class='btn btn-default btn-calendar'>달력</button>
							</span>
						</div>
					</div>
					<div class="input-group-wrapper">
						<div class='input-group date' id='picker2'>
							<input id='p2val' type='text' class="form-control"
								data-format='YYYY/MM/DD' readonly='readonly'
								value="<?php echo date('Y/m/d');?>" /> <span
								class='input-group-addon input-group-addon-end'>
								<button class='btn btn-default btn-calendar'>달력</button>
							</span>
						</div>
					</div>
				</div>
			</div>
			<div class="col-md-4 button_align">
				<div class="btn-group">
					<button class="btn btn-lg btn-primary" type="button"
						onclick="location.href='./employee_detail.php?pageType=1'">인력 생성</button>
					<button class="btn btn-lg btn-primary" type="submit"
						onclick="location.href='./vehicle_detail.php?pageType=1'">차량 생성</button>
					<button class='btn btn-lg btn-primary' type='submit'
						onclick="location.href='./gnuboard4/'">게시판 관리</button>
				</div>
				<?php
				if ($login->getGrade () == 1) {
					echo "<div class='btn-group'><button class='btn btn-lg btn-info' type='button' onclick='location.href=\"./category.php\"'>분류 관리</button>";
					echo "<button class='btn btn-lg btn-info' type='submit' onclick='location.href=\"./outgoings.php\"'>지출 내역</button>";
					// echo "<button class='btn btn-lg btn-info' type='submit' onclick='location.href=\"#\"'>지출 내역</button>";
					echo "<button class='btn btn-lg btn-info' type='submit' onclick='location.href=\"./daily_report.php?type=1\"'>일결산 생성</button></div>";
				}
				?>
				<?php
				if ($login->getGrade () == 1) {
					echo "<div class='btn-group'><button class='btn btn-lg btn-info' type='button' onclick='javascript:excelDown()'>엑셀 받기</button></div>";
					//echo "<button class='btn btn-lg btn-info' type='submit' onclick='location.href=\"./outgoings.php\"'>지출 내역</button>";
					// echo "<button class='btn btn-lg btn-info' type='submit' onclick='location.href=\"#\"'>지출 내역</button>";
					//echo "<button class='btn btn-lg btn-info' type='submit' onclick='location.href=\"./daily_report.php?type=1\"'>일결산 생성</button></div>";
				}
				?>
			</div>
		</div>
		<div class="table-responsive" id="table_div" style="overflow: scroll;">
			<table id="table" class="table table-hover tablesorter">
				<thead id="table_head">
					<tr>
						<th>사원번호</th>
						<th>성명</th>
						<th>운전면허번호</th>
						<th>화물자격번호</th>
						<th>사업자등록번호</th>
						<th>회원등급</th>
						<th>직책</th>
						<th>운송료결산일</th>
						<th>이메일</th>
						<th>주소</th>
						<!-- <th>거래처</th> -->
						<th>차량</th>
						<th>연락처</th>
						<th>기본 운송료</th>
						<!-- <th>직영구분</th> -->
					</tr>
				</thead>
				<tbody id="tbodyInfo">
					<!-- 					<tr> -->
					<!-- 						<td colspan="28">검색된 결과가 없습니다.</td> -->
					<!-- 					</tr> -->
				</tbody>
			</table>
		</div>
		<div id="pager" class="pager">
			<form>
				<input type="button" value="&lt;&lt;" class="first btn btn-default" />
				<input type="button" value="&lt;" class="prev btn btn-info" /> Page:
				<select class="gotoPage"></select> <input type="button" value="&gt;"
					class="next btn btn-info" /> <input type="button" value="&gt;&gt;"
					class="last btn btn-default" />
				<div style="margin-top: 10px">
					<span type="text" class="pagedisplay"></span> Row: <select
						class="pagesize">
						<option selected="selected" value="10">10</option>
						<option value="20">20</option>
						<option value="30">30</option>
						<option value="40">40</option>
					</select>
				</div>

			</form>
		</div>
	</div>
	<!-- /container -->
	<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
	<script src="./dist/js/bootstrap.min.js"></script>
	<script type="text/javascript"
		src="./lib/tablesorter-master/js/jquery.tablesorter.js"></script>
	<script type="text/javascript"
		src="./lib/tablesorter-master/js/jquery.tablesorter.widgets.js"></script>
	<script src="./lib/tablesorter-master/js/widgets/widget-pager.js"></script>
	<script type="text/javascript" src="./lib/moment/moment.js"></script>
	<script type="text/javascript" src="./lib/moment/transition.js"></script>
	<script type="text/javascript" src="./lib/moment/collapse.js"></script>
	<script type="text/javascript"
		src="./lib/datetimepicker/bootstrap-datetimepicker.min.js"></script>

	<script type="text/javascript">
	$(window).load(function () {
		$('#picker1').datetimepicker({
			pickTime: false
		});
		$('#picker2').datetimepicker({
			pickTime: false
		});
		$("#picker1").on("change.dp",function (e) {
            $('#picker2').data("DateTimePicker").setStartDate(e.date);
         });
         $("#picker2").on("change.dp",function (e) {
            $('#picker1').data("DateTimePicker").setEndDate(e.date);
         });

         changeDelemiter(document.getElementById("table_selection"));
	});
	</script>
	<script type="text/javascript">
		$(function() {
			addTableSorter();
		});
	</script>
	<script>
	$(window).load(function () {
		window.parent.document.title = 'Koreanet >> 관리자';
	});
	function excelDown()
	{
		location.href='./XLS.php?type='+document.getElementById("table_selection").value
		+'&sDate='+document.getElementById("p1val").value
		+'&eDate='+document.getElementById("p2val").value;
	}
    </script>
</body>
</html>